const db = require("../lib/db")
function classifyArticleList(_id){

    return new Promise((resolve , reject)=>{
        let sql = "select * from article where classify ='" + _id + "' " 
        db.querySql(sql).then(data => {
            if(data.length == 0){
                resolve(501)
            }else{
                let arr = data.sort(()=>0.5 - Math.random())
                console.log(arr);
                let arr2 = []
                arr.map(element => {
                    arr2.push({
                        _id : element._id,
                        title : element.title,
                        content : element.content,
                        descs : element.descs,
                        time : element.time,
                        author : element.author,
                        authorId : element.authorId,
                        classify : element.classify,
                        __v : element.__v
                    })
                })
                resolve(arr2);
            }     
        })
    })
}
module.exports = classifyArticleList